<template>
  <div class="personal">
    <router-link :to="{path: `/editPerson/${currentUser.id}`}">
      <div class="profile">
        <!-- $axios.defaults.baseURL读取axios的服务器路径 -->
        <img :src="currentUser.head_img" alt />
        <div class="profile-center">
          <div class="name">
            <span class="iconfont iconxingbienan"></span>{{currentUser.nickname}}
          </div>
          <div class="time">{{currentUser.create_date}}</div>
        </div>
        <span class="iconfont iconjiantou1"></span>
      </div>
    </router-link>
    <cell title="我的关注" desc="关注的用户" @click="$router.push({name:'Myfollow'})"></cell>
    <cell title="我的跟帖" desc="跟帖/回复" ></cell>
    <cell title="我的收藏" desc="文章/视频" @click="$router.push({name:'myStars'})"></cell>
    <cell title="设置"></cell>
    <mybutton class="btn" @click="exit">退出</mybutton>
  </div>
</template>

<script>
import cell from '../components/cell.vue';
import mybutton from '../components/mybutton.vue';
import { personData } from '../apis/users.js';
export default {
  data() {
    return {
      currentUser:{}
    };
  },
  components: {
    cell,
    mybutton
  },
  async mounted() {
    let id = this.$route.params.id;
    let res = await personData(id);
    // console.log(res); //此时文档说设置了验证，所以需要设置拦截器
    if(res.data.message === '获取成功') {
      this.currentUser = res.data.data;
      this.currentUser.head_img ='http://127.0.0.1:3000' + res.data.data.head_img
      
      // console.log(this.currentUser.create_date.format("yyyy-MM-dd"));
      
    }
  },
  methods: {
    exit() {
      this.$router.push({name: 'index'});
      localStorage.removeItem('this_token')
    }
  }
};
</script>

<style lang='less' scoped>
.personal {
  width: 100vw;
  height: 100vh;
  background-color: #eee;
}
a {
  color: #666;
}
.profile {
  display: flex;
  padding: 20px 10px;
  justify-content: space-between;
  align-items: center;
  border-bottom: 5px #ddd solid;

  img {
    width: 70 / 360 * 100vw;
    height: 70 / 360 * 100vw;
    border-radius: 50%;
  }

  .profile-center {
    flex: 1;
    padding: 0 10px;
  }

  .name {
    span {
      color: #75b9eb;
    }
  }

  .time {
    color: #666;
    font-size: 14px;
    margin-top: 5px;
  }
}
.btn {
  margin-top: 30px;
}
</style>
